package com.example.controller;

import com.example.common.Result;
import com.example.entity.Choice;
import com.example.entity.Course;
import com.example.service.ChoiceService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/choice")
public class ChoiceController {
    @Autowired
    private ChoiceService choiceService;

    /**
     * 选课功能
     */
    @PostMapping("/add")
    public Result add(@RequestBody Course course) {
        choiceService.add(course);
        return Result.success();
    }

    /**
     * 分页和条件查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize,
                             Choice choice){
        PageInfo<Choice> pageInfo = choiceService.selectPage(pageNum,pageSize,choice);
        return Result.success(pageInfo);
    }

    /**
     * 取消选课
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        choiceService.deleteById(id);
        return Result.success();
    }

}
